<%@page import="java.sql.ResultSet"%>
<%@page import="database.DBConnector"%>
<%
        String tlf = request.getParameter("req");
        DBConnector dbc = DBConnector.getDBC();
        boolean exists = false;
        try {
            int intTLF = Integer.parseInt(tlf);
            ResultSet rs = dbc.doQuery("SELECT TelephoneNumber from Customers WHERE TelephoneNumber='" + intTLF + "'");
            while (rs.next()) {
                exists = true;
            }
            if (!exists) {
                if (tlf.length() != 8) {
                    out.println("<img id=\"valid_tlf\" alt=\":(\" src=\"../pictures/invalid.jpg\"/>");
                    session.setAttribute("VALID_TLF", "FALSE");
                } else {
                    out.println("<img id=\"valid_tlf\" alt=\":)\" src=\"../pictures/valid.jpg\"/>");
                    session.setAttribute("VALID_TLF", "TRUE");
                }
            } else {
                out.println("<img id=\"valid_tlf\" alt=\":)\" src=\"../pictures/invalid.jpg\"/> Telefonnummer findes allerede!");
                session.setAttribute("VALID_TLF", "FALSE");
            }
        } catch (Exception ex) {
            out.println("<img id=\"valid_tlf\" alt=\":(\" src=\"../pictures/invalid.jpg\"/>");
            session.setAttribute("VALID_TLF", "FALSE");
        }
%>
